home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 426-450 / disk_447 / sman / cp / smancp.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  22KB  |  956 lines

  1. #include    "functions.h"
  2. #include    "exec/types.h"    /*Needed for SOFFSET macro*/
  3. #include    "exec/execbase.h"
  4. #include    "exec/tasks.h"
  5. #include    "exec/memory.h"
  6. #include    "exec/ports.h"
  7. #include    "clib/graphics_protos.h"
  8. #include    "graphics/view.h"
  9. #include    "graphics/gfx.h"
  10. #include    "graphics/gfxbase.h"
  11. #include    "graphics/gfxmacros.h"
  12. #include    "graphics/rastport.h"
  13. #include    "intuition/intuitionbase.h"
  14. #include    "intuition/intuition.h"
  15. #include    "intuition/preferences.h"
  16. #include    "libraries/dos.h"
  17. #include    "libraries/dosextens.h"
  18. #include    "stdio.h"
  19. #include    "exec/io.h"
  20. #include    "iff/iff.h"
  21. #include    "iff/ilbm.h"
  22.  
  23. double XWidth,XHeight,XCenter,YCenter,HWidth,HHeight,Factor;
  24. double LastX,LastY,LastFactor;
  25. LONG    xtemp,ytemp,MaxCnt,CurCnt,XC,YC,LeftEdge,RightEdge,NearEdge,FarEdge;
  26. LONG    S1Height,S1Width,MltPlr;
  27. ULONG    *PlnPtr;
  28.  
  29. BPTR    FileHandle;
  30. #define    Pf_Size    0xe8
  31. #define    ScnFlg    0x1;
  32. #define    LacFlg    0x2;
  33. #define    ChdFlg    DefFlg | CHECKIT | CHECKED
  34. #define    ChkFlg    DefFlg | CHECKIT
  35.  
  36. CmpFlg    = MOUSEBUTTONS | MENUPICK;
  37. MyFlag     =    NOCAREREFRESH|REPORTMOUSE|BORDERLESS;
  38. MenFlg     =    MENUENABLED | MIDRAWN;
  39. DefFlg     =    ITEMTEXT|COMMSEQ|ITEMENABLED|HIGHCOMP;
  40.  
  41.  
  42. struct Library *DOSBase;
  43. struct GfxBase *GfxBase;
  44. struct IntuitionBase *IntuitionBase;
  45. struct ExecBase    *SysBase;
  46. struct    Gadget    *GadStuff;
  47. struct    NewScreen    ns;
  48. struct    NewWindow    nw;
  49. BYTE    CurrentXOffset;
  50. BYTE    CurrentYOffset;
  51. UBYTE    Title[] = "                          Julian Explorer";
  52. UBYTE    *WindowName;
  53. SHORT    SWidth,SHeight;
  54. USHORT    MyView,SUFlag,SysFlag,ScnSts,OvsChk,LacChk,LacMod,NLcChk,MenVal,NrmChk;
  55. struct    Screen    *IntScreen;
  56. struct    Screen    *WBScreen;
  57. struct    Window    *InfoWindow;
  58. struct    Window    *IntWindow;
  59. struct    MsgPort    *MyPort,*IntPort;
  60. struct    RastPort    *MyRasta,*WBRast,*CWRast;
  61. struct    ViewPort    VPorta,VPortb;
  62. struct    Preferences    MyNewPrefs,*CurPrefs;
  63. struct    Menu        Menu1,Menu2,Menu3,Menu4;
  64. struct    MenuItem    *MIStruct;
  65. struct    IntuiText    *ITStruct;
  66.  
  67. struct    MenuItem    MI11,MI12,MI13,MI14;
  68. struct    MenuItem    MI21,MI22,MI23,MI24;
  69. struct    MenuItem    MI31,MI32,MI33,MI34;
  70. struct    MenuItem    MI41,MI42,MI43,MI44;
  71. struct    IntuiText    IT11,IT12,IT13,IT14;
  72. struct    IntuiText    IT21,IT22,IT23,IT24;
  73. struct    IntuiText    IT31,IT32,IT33,IT34;
  74. struct    IntuiText    IT41,IT42,IT43,IT44;
  75.  
  76. struct    PLANEPTR    *PlanePtrA,*PlanePtrB;
  77. static    char    Message[]     = "by David M. McKinstry";
  78. static    char    Mesag2[]    = "Copyright ";
  79. UBYTE    Mesag2b[]    = 0xa9;
  80. UBYTE    Comma[] = 0x2c;
  81. static    char    Mesag2c[]    = " 1989-91";
  82. static    char    Mesag3[]    = "System Hardware: ";
  83. static    char    Mesag4[]    = "Use the menu options on the Custom Screen to change the following parameters!";
  84. static    char    Mesag5[]    = "Click on the Close Gadget to bring the Custom Screen forward!";
  85. static    char    Mesag6[]    = "(Note:  This window won't be closed, just hidden.)";
  86. static    char    Mesag7[]    = "To return to this WorkBench Screen, select 'About' from the SManCP menu!";
  87. static    char    ScrMsg[]    = "Screen center is at ";
  88. static    char    ChpMsg[]    = "Chip Memory Free = ";
  89. static    char    ChpEnd[]    = "                ";
  90. static    char    FstMsg[]    = "Fast Memory Free = ";
  91. static    char    FstEnd[]    = "                ";
  92. static    char    WdtMsg[]    = "Screen Width =  ";
  93. static    char    WdtEnd[]    = "        ";
  94. static    char    HgtMsg[]    = "Screen Height = ";
  95. static    char    HgtEnd[]    = "        ";
  96. static    char    MagMsg[]    = "Magnification = ";
  97. static    char    MagEnd[]    = "                  ";
  98. static    char    XPos[]        = "x = ";
  99. static    char    XPsEnd[]    = "                  ";
  100. static    char    YPos[]        = "y = ";
  101. static    char    YPsEnd[]    = "                  ";
  102. static    char    CntMsg[]    = "Maximum Count = ";
  103. static    char    CntEnd[]    = "        ";
  104.  
  105. static    char    StrngBuffer[200];
  106. SHORT    VertPos;
  107. USHORT    CTable[] = {0,0xf00,0xff0,0x3f8,0x5ea,0xf3a,0x0de,0xf80,0x9f0,0x7df,0x69f,
  108.                     0x00f,0xf2e,0xc0e,0x60e,0x607};
  109.  
  110. SHORT    PolyTab[10];
  111. SHORT    *PolyPnt;
  112. SHORT DeltaX,DeltaY;
  113. SHORT    x1,y1,x2,y2;
  114. ULONG    IMClass;
  115.  
  116. ScanOn()
  117. {
  118.     NrmChk = ChkFlg;
  119.     OvsChk = ChdFlg;
  120.     SWidth = 704;
  121.     SHeight = 478;
  122.     S1Width = 703;
  123.     S1Height = 477;
  124.     XC = 352;
  125.     YC = 239;
  126.     NearEdge = 0;
  127.     LeftEdge = 0;
  128.     RightEdge = 704;
  129.     FarEdge = 478;
  130.     ScnSts = 1;    /* Indicate overscan on */
  131. }
  132.  
  133. ScnOff()
  134. {
  135.     NrmChk = ChdFlg;
  136.     OvsChk = ChkFlg;
  137.     SWidth = 640;
  138.     SHeight = 400;
  139.     S1Width = 639;
  140.     S1Height = 399;
  141.     XC = 320;
  142.     YC = 199;
  143.     NearEdge = 0;
  144.     LeftEdge = 0;
  145.     RightEdge = 640;
  146.     FarEdge = 400;
  147.     ScnSts = 0;    /* Change to no overscan */
  148. }
  149.  
  150. LaceOff()
  151. {
  152.     MyView = HIRES;
  153.     LacChk = ChkFlg;
  154.     NLcChk = ChdFlg;
  155.     LacMod = 0;
  156.     SHeight = SHeight/2;
  157.     S1Height = SHeight;
  158.     --S1Height;
  159.     FarEdge = FarEdge/2;
  160. }
  161.  
  162. LaceOn()
  163. {
  164.     MyView = HIRES | LACE;
  165.     LacChk = ChdFlg;
  166.     NLcChk = ChkFlg;
  167.     LacMod = 1;
  168. }
  169. ScnSet()
  170. {
  171.     if (SUFlag & 0x2)    {
  172.         LaceOn();
  173.         }
  174.     else LaceOff();
  175. }
  176.  
  177. ViewSet()
  178. {
  179.     if (SUFlag & 0x1)    {    /* See if Overscan flag set */
  180.         ScanOn();
  181.         ScnSet();
  182.         }
  183.     else {
  184.         ScnOff();
  185.         ScnSet();
  186.         }
  187. }
  188.  
  189.  
  190. void ITInit(Item,NamePtr)
  191. struct    IntuiText    *Item;
  192. UBYTE    *NamePtr;
  193. {
  194.     Item -> IText = NamePtr;
  195.     Item -> BackPen = 3;
  196.     Item -> FrontPen = 5;
  197.     Item -> DrawMode = JAM1;
  198. }
  199. MIInit(Item,NxtItem,TEdge,Cmd,ITItem,Width)
  200. struct    MenuItem    *Item,*NxtItem;
  201. APTR    ITItem;
  202. SHORT    TEdge,Width;
  203. BYTE    Cmd;
  204. {
  205.     Item -> Command = Cmd;
  206.     Item -> TopEdge = TEdge;
  207.     Item -> NextItem = NxtItem;
  208.     Item -> ItemFill = (APTR)ITItem;
  209.     Item -> Flags = (USHORT)DefFlg;
  210.     Item -> Height = 9;
  211.     Item -> Width = Width;
  212. }
  213.  
  214. void MenuInit(MenuStruct,NxtMenu,NamePtr,LEdge,MWidth)
  215. struct Menu    *MenuStruct,*NxtMenu;
  216. SHORT    LEdge,MWidth;
  217. BYTE    *NamePtr;
  218. {
  219.     MenuStruct -> NextMenu = NxtMenu;
  220.     MenuStruct -> Width = MWidth;
  221.     MenuStruct -> Height = 9;
  222.     MenuStruct -> LeftEdge = LEdge;
  223.     MenuStruct -> TopEdge = 0;
  224.     MenuStruct -> MenuName = NamePtr;
  225.     MenuStruct -> Flags = MenFlg;
  226.  
  227. }
  228.  
  229. void ScreenSet()
  230. {
  231. SHORT    MWidth,MHeight,LEdge,TEdge;
  232. UBYTE    MICommand;
  233. struct    Menu    *MenStrct;
  234. BOOL Test;
  235. ns.LeftEdge    =    0;
  236. ns.TopEdge     =   0;        /*Was 20 */
  237. ns.Width       =  SWidth;
  238. ns.Height      =  SHeight;
  239. ns.DetailPen   =   0;
  240. ns.BlockPen    =   1;
  241. ns.Depth       =   4;
  242. ns.ViewModes   =   MyView;
  243.  
  244.     IntScreen = (struct Screen *)OpenScreen( &ns );
  245.     PlanePtrA = (struct PLANEPTR *)(IntScreen -> BitMap.Planes);
  246.     MyRasta = &(IntScreen -> RastPort);
  247.     VPorta = IntScreen -> ViewPort;
  248.     LoadRGB4(&VPorta,&CTable[0],16);
  249.     if (ScnSts)    {
  250. /*        MyNewPrefs.ViewXOffset = 0xdc;
  251.         MyNewPrefs.ViewYOffset = 0xe9;*/
  252.         MyNewPrefs.ViewXOffset = 0xde;
  253.         MyNewPrefs.ViewYOffset = 0xed;
  254.         }
  255.     else    {
  256.         MyNewPrefs.ViewXOffset = CurrentXOffset;
  257.         MyNewPrefs.ViewYOffset = CurrentYOffset;
  258.         }
  259.     SetPrefs(&MyNewPrefs,Pf_Size,FALSE);
  260.  
  261.     nw.Title = NULL;
  262. nw.LeftEdge        =    0;
  263. nw.TopEdge        =    0;
  264. nw.Width        =    SWidth;
  265. nw.Height        =    SHeight;
  266. nw.DetailPen    =    5;
  267. nw.BlockPen        =    2;
  268. /*nw.IDCMPFlags    =    GADGETUP | MENUPICK;*/
  269. nw.IDCMPFlags    =    CmpFlg;
  270. nw.Type            =    CUSTOMSCREEN;
  271. nw.Flags        =    MyFlag;    ACTIVATE | SMART_REFRESH;
  272. nw.FirstGadget    =    NULL;
  273. nw.CheckMark    =    NULL;
  274. nw.Screen        =    IntScreen;
  275. nw.BitMap        =    NULL;
  276. nw.MinWidth        =    320;
  277. nw.MinHeight    =    100;
  278. nw.MaxWidth        =    SWidth;
  279. nw.MaxHeight    =    SHeight;
  280.  
  281.     IntWindow = (struct Window *)OpenWindow( &nw );
  282.  
  283. /* Get associated information about Int window */
  284. /*    GadStuff = IntWindow -> FirstGadget;*/
  285.     CWRast = IntWindow -> RPort;
  286.     SetRast(CWRast,0);
  287.     IntPort    = IntWindow -> UserPort;
  288.  
  289. /*    Template is 
  290.     MenuInit(&Menu1,&Menu2,"Strng",LEdge,MWidth);
  291.         */
  292.  
  293.     MenuInit(&Menu1,&Menu2,"SManCP",20,100);
  294.     Menu1.FirstItem = &MI11;
  295.     MIInit(&MI11,&MI12,0,0x41,&IT11,150);    
  296.     MIInit(&MI12,&MI13,9,0x52,&IT12,150);
  297.     MIInit(&MI13,&MI14,18,0x53,&IT13,150);
  298.     MIInit(&MI14,0,27,0x51,&IT14,150);    
  299.  
  300.     ITInit(&IT11,"About");
  301.     ITInit(&IT12,"Redraw(Same P)");
  302.     ITInit(&IT13,"Save");
  303.     ITInit(&IT14,"Quit");
  304.  
  305.     MenuInit(&Menu2,&Menu3,"View Mode",180,130);
  306.     Menu2.FirstItem = &MI21;
  307.     MIInit(&MI21,&MI22,0,0x4c,&IT21,150);    
  308.     MIInit(&MI22,&MI23,9,0x43,&IT22,150);
  309.     MIInit(&MI23,&MI24,18,0x4d,&IT23,150);
  310.     MIInit(&MI24,0,27,0x4e,&IT24,150);    
  311.  
  312.     ITInit(&IT21,"   Lace On");
  313.     ITInit(&IT22,"   Lace Off");
  314.     ITInit(&IT23,"   Overscan");
  315.     ITInit(&IT24,"   Normal");
  316.  
  317.     MenuInit(&Menu3,&Menu4,"Maximum Count",350,130);
  318.     Menu3.FirstItem = &MI31;
  319.     MIInit(&MI31,&MI32,0,43,&IT31,150);    
  320.     MIInit(&MI32,&MI33,9,45,&IT32,150);
  321.     MIInit(&MI33,&MI34,18,0x44,&IT33,150);
  322.     MIInit(&MI34,0,27,0x48,&IT34,150);    
  323.  
  324.     ITInit(&IT31,"Increase by 10");
  325.     ITInit(&IT32,"Decrease by 10");
  326.     ITInit(&IT33,"Double");
  327.     ITInit(&IT34,"Halve");
  328.  
  329.  
  330.     MenuInit(&Menu4,0,"Zoom",505,100);
  331.     Menu4.FirstItem = &MI41;
  332.     MIInit(&MI41,&MI42,0,0x5a,&IT41,140);    
  333.     MIInit(&MI42,0,9,0x49,&IT42,140);    
  334.  
  335.     ITInit(&IT41,"Select");
  336.     ITInit(&IT42,"Restore");
  337.  
  338.     MI21.Flags = LacChk;
  339.     MI22.Flags = NLcChk;
  340.     MI23.Flags = OvsChk;
  341.     MI24.Flags = NrmChk;
  342. /*    Test = SetMenuStrip(IntWindow,&Menu1);*/
  343.     SetMenuStrip(IntWindow,&Menu1);
  344.  
  345.     ActivateWindow(InfoWindow);
  346. }
  347.  
  348. void ScreensClose()
  349. {
  350.     if(InfoWindow) CloseWindow(InfoWindow);
  351.     if(IntWindow) CloseWindow(IntWindow);
  352.     if(IntScreen) CloseScreen(IntScreen);
  353. }
  354. void ScreenClose()
  355. {
  356.     if(IntWindow) ClearMenuStrip(IntWindow);
  357.     if(IntWindow) CloseWindow(IntWindow);
  358.     if(IntScreen) CloseScreen(IntScreen);
  359. }
  360.  
  361.  
  362. OpenWrite()
  363. {
  364.     FileHandle = Open((UBYTE *)"Mand.iff",MODE_NEWFILE);
  365.     if (!FileHandle)    return(-1);
  366.     return(0);
  367. }
  368.  
  369. WriteFile(Source,FileLength)
  370. char    *Source;
  371. ULONG    FileLength;
  372. {
  373. ULONG    Count,*Destination;
  374. ULONG    ReadLength;
  375.     Write(FileHandle,(char *)Source,FileLength);
  376.     return(0);
  377. }
  378. CloseWrite()
  379. {
  380.     Close(FileHandle);
  381. }
  382.  
  383. ULONG WritePlanes()
  384. {
  385. USHORT    PlnCnt,LineCount;
  386.  
  387. ULONG    Count,*Source1,*Source2,*Source3,*Source4;
  388. ULONG    FileLength,LineLength;
  389.     FileLength = 32000;
  390.     Source1 = (ULONG *)*PlnPtr++;
  391.     Source2 = (ULONG *)*PlnPtr++;
  392.     Source3 = (ULONG *)*PlnPtr++;
  393.     Source4 = (ULONG *)*PlnPtr++;
  394.     LineCount = ns.Height;
  395.     FileLength = ns.Width >> 3;
  396.     LineLength = FileLength >> 2; /* # of long words on line */
  397.     while (LineCount)    {
  398.         FileLength = Write(FileHandle,(char *)Source1,FileLength);
  399.         Source1 = Source1 + LineLength;
  400.         FileLength = Write(FileHandle,(char *)Source2,FileLength);
  401.         Source2 = Source2 + LineLength;
  402.         FileLength = Write(FileHandle,(char *)Source3,FileLength);
  403.         Source3 = Source3 + LineLength;
  404.         FileLength = Write(FileHandle,(char *)Source4,FileLength);
  405.         Source4 = Source4 + LineLength;
  406.         --LineCount;
  407.         }
  408.     return(0);
  409. }
  410.  
  411.  
  412. Save()
  413. {
  414. ULONG    *HdrSize,*HdrTop,*HdrBottom;
  415. UBYTE    *MyColors;
  416. USHORT    *CurrentColor,Red,Green,Blue;
  417. /*static    char    MandName[] = "Mand.iff";*/
  418. ChunkHeader        *Chunk3D;
  419. BitMapHeader    *MyHeader;
  420.  
  421. typedef        struct    {
  422.     ID        ckID;
  423.     }    sChunk;
  424.  
  425. sChunk    *ChunkID;
  426. char    *HdrBuffer;
  427.  
  428. ULONG    CTSize,CTCount,FileLength,BodyLength,Depth;
  429.     HdrBuffer = AllocMem(160,MEMF_PUBLIC|MEMF_CLEAR);
  430.     Chunk3D = (ChunkHeader *) HdrBuffer;
  431.     Chunk3D -> ckID = FORM;
  432.     Chunk3D++;
  433.     ChunkID = (sChunk *) Chunk3D;
  434.     ChunkID -> ckID = ID_ILBM;
  435.     ChunkID++;
  436.     ChunkID -> ckID = ID_BMHD;
  437.     ChunkID++;
  438.     HdrSize = (ULONG *)ChunkID;
  439.     *HdrSize++ = 20;
  440.     MyHeader = (BitMapHeader *)HdrSize;
  441.     MyHeader -> w = ns.Width;
  442.     MyHeader -> h = ns.Height;
  443.     CTCount = ns.Depth;
  444.     MyHeader -> nPlanes = CTCount;
  445.     MyHeader -> xAspect = 1;
  446.     MyHeader -> yAspect = 1;
  447.     MyHeader -> pageWidth = ns.Width;
  448.     MyHeader -> pageHeight = ns.Height;
  449.     MyHeader++;
  450.     Chunk3D = (ChunkHeader *)MyHeader;
  451.     Chunk3D -> ckID = ID_CMAP;
  452.     CTSize = 1;
  453.     while (CTCount)    {
  454.         CTSize <<= 1;
  455.         --CTCount;
  456.         }
  457.     Chunk3D -> ckSize = 3*CTSize;
  458.     Chunk3D++;
  459.     MyColors = (UBYTE *)Chunk3D;
  460.     CTCount = ns.Depth;
  461.     CurrentColor = &CTable[0];
  462.     while (CTSize)    {
  463.         Red = *CurrentColor;
  464.         Red = 0xf00 & Red;
  465.         Red >>= 4;
  466.         *MyColors++ = (UBYTE)Red;
  467.         Green = *CurrentColor;
  468.         Green = 0xf0 & Green;
  469.         *MyColors++ = (UBYTE)Green;
  470.         Blue = *CurrentColor++;
  471.         Blue = 0xf & Blue;
  472.         Blue <<= 4;
  473.         *MyColors++ = (UBYTE)Blue;
  474.         --CTSize;
  475.         }
  476.     Chunk3D = (ChunkHeader *)MyColors;
  477.     Chunk3D -> ckID = ID_BODY;
  478.     CTCount = ns.Width;
  479.     CTCount >>= 3;
  480.     CTCount = CTCount*ns.Height;
  481.     CTCount = CTCount*ns.Depth;
  482.     Chunk3D -> ckSize = CTCount;
  483.     BodyLength = CTCount;
  484.     Chunk3D++;
  485.     HdrTop = (ULONG *)Chunk3D;
  486.     HdrBottom = (ULONG *)HdrBuffer;
  487.     FileLength = HdrTop - HdrBottom;
  488.     FileLength <<= 2;    /* Get # bytes */
  489.     Chunk3D = (ChunkHeader *)HdrBuffer;
  490.     CTCount = CTCount + FileLength;
  491.     Chunk3D -> ckSize = CTCount - 8;
  492.     OpenWrite();
  493.     WriteFile(HdrBuffer,FileLength);
  494.     PlnPtr = (ULONG *) PlanePtrA;
  495.     WritePlanes();
  496.     CloseWrite();        
  497.     if (HdrBuffer) FreeMem(HdrBuffer,160);
  498.     return(0);
  499. }
  500.  
  501. void WindowSet()
  502. {
  503.  
  504. nw.LeftEdge        =    0;
  505. nw.TopEdge        =    0;            /* Expose screen drag bar */
  506. nw.Width        =    640;
  507. nw.Height        =    200;
  508. nw.DetailPen    =    5;
  509. nw.BlockPen        =    2;
  510. nw.IDCMPFlags    =    CLOSEWINDOW;
  511. nw.Type            =    WBENCHSCREEN;
  512. nw.Flags        =    WINDOWDRAG|WINDOWDEPTH|WINDOWCLOSE|SMART_REFRESH|ACTIVATE|REPORTMOUSE;
  513. nw.FirstGadget    =    NULL;
  514. nw.CheckMark    =    NULL;
  515. nw.Screen        =    0;
  516. WindowName     = &Title[0];
  517. nw.Title        =    (UBYTE *)WindowName;
  518. nw.BitMap        =    NULL;
  519. nw.MinWidth        =    320;
  520. nw.MinHeight    =    100;
  521. nw.MaxWidth        =    SWidth+20;
  522. nw.MaxHeight    =    SHeight+20;
  523.  
  524.     InfoWindow = (struct Window *)OpenWindow( &nw );
  525.     WBRast = InfoWindow -> RPort;    
  526.     MyPort    = InfoWindow -> UserPort;
  527.     WBScreen = InfoWindow -> WScreen;
  528. }
  529.  
  530. void DescribeSystem()
  531. {
  532.     if (SysFlag & AFB_68030) Text(WBRast,(STRPTR)" 68030",6);
  533.     else if (SysFlag & AFB_68020) Text(WBRast,(STRPTR)" 68020",6);
  534.     Text(WBRast,(STRPTR)Comma,1);
  535.     if (SysFlag & AFB_68882) Text(WBRast,(STRPTR)" 68882",6);
  536.     else if (SysFlag & AFB_68881) Text(WBRast,(STRPTR)" 68881",6);
  537. }
  538.  
  539. void WriteStuff()
  540. {
  541. ULONG    MemSize;
  542. char *TmpPtr;
  543.     SetAPen(WBRast,1);
  544.     Move(WBRast,0xd0,20);
  545.     Text(WBRast,(STRPTR)Message,strlen(Message));
  546.     SetAPen(WBRast,3);
  547.     Move(WBRast,0xd8,30);
  548.     Text(WBRast,(STRPTR)Mesag2,strlen(Mesag2));
  549.     Text(WBRast,(STRPTR)Mesag2b,1);
  550.     Text(WBRast,(STRPTR)Mesag2c,strlen(Mesag2c));
  551.     Move(WBRast,0xe0,128);
  552.     Text(WBRast,(STRPTR)ScrMsg,strlen(ScrMsg));
  553.     SetAPen(WBRast,1);
  554.     Move(WBRast,0x90,48);
  555.     Text(WBRast,(STRPTR)Mesag3,strlen(Mesag3));
  556.     DescribeSystem();
  557.     SetAPen(WBRast,2);
  558.     Move(WBRast,8,78);
  559.     Text(WBRast,(STRPTR)Mesag4,strlen(Mesag4));
  560.     Move(WBRast,0x40,152);
  561.     Text(WBRast,(STRPTR)Mesag5,strlen(Mesag5));
  562.     Move(WBRast,0x60,162);
  563.     Text(WBRast,(STRPTR)Mesag6,strlen(Mesag6));
  564.     Move(WBRast,0x18,172);
  565.     Text(WBRast,(STRPTR)Mesag7,strlen(Mesag7));
  566.     SetAPen(WBRast,1);
  567.     TmpPtr = &CntEnd[0];
  568.     --TmpPtr;
  569.     sprintf(TmpPtr,"%d",MaxCnt);
  570.     Move(WBRast,400,108);
  571.     Text(WBRast,(STRPTR)CntMsg,strlen(CntMsg));
  572.     Move(WBRast,0x28,60);
  573.     MemSize = AvailMem(MEMF_CHIP);
  574.     TmpPtr = &ChpEnd[0];
  575.     --TmpPtr;
  576.     sprintf(TmpPtr,"%d",MemSize);
  577.     Text(WBRast,(STRPTR)ChpMsg,strlen(ChpMsg));
  578.     Move(WBRast,400,60);
  579.     MemSize = AvailMem(MEMF_FAST);
  580.     TmpPtr = &FstEnd[0];
  581.     --TmpPtr;
  582.     sprintf(TmpPtr,"%d",MemSize);
  583.     Text(WBRast,(STRPTR)FstMsg,strlen(FstMsg));
  584.     Move(WBRast,0x28,94);
  585.     TmpPtr = &WdtEnd[0];
  586.     --TmpPtr;
  587.     sprintf(TmpPtr,"%d",SWidth);
  588.     Text(WBRast,(STRPTR)WdtMsg,strlen(WdtMsg));
  589.     Move(WBRast,400,94);
  590.     TmpPtr = &HgtEnd[0];
  591.     --TmpPtr;
  592.     sprintf(TmpPtr,"%d",SHeight);
  593.     Text(WBRast,(STRPTR)HgtMsg,strlen(HgtMsg));
  594.     Move(WBRast,0x28,108);
  595.     TmpPtr = &MagEnd[0];
  596.     --TmpPtr;
  597.     sprintf(TmpPtr,"%e",Factor);
  598.  
  599.     Text(WBRast,(STRPTR)MagMsg,strlen(MagMsg));
  600.     Move(WBRast,0x28,136);
  601.     TmpPtr = &XPsEnd[0];
  602.     --TmpPtr;
  603.     sprintf(TmpPtr,"%e",(HWidth-XCenter)/Factor);
  604.     Text(WBRast,(STRPTR)XPos,strlen(XPos));
  605.     Move(WBRast,400,136);
  606.     TmpPtr = &YPsEnd[0];
  607.     --TmpPtr;
  608.     sprintf(TmpPtr,"%e",(HHeight-YCenter)/Factor);
  609.     Text(WBRast,(STRPTR)YPos,strlen(YPos));
  610. }
  611.  
  612.     
  613. void LibsOpen()
  614. {
  615.     if (!DOSBase)    {
  616.         DOSBase = (struct Library *)OpenLibrary((UBYTE *)"dos.library",0L);
  617.         }
  618.  
  619.     GfxBase = (struct GfxBase *)OpenLibrary((UBYTE *)"graphics.library",0L);
  620.     IntuitionBase = (struct IntuitionBase *)OpenLibrary((UBYTE *)"intuition.library",0L);
  621. }
  622.  
  623. void LibsClose()
  624. {
  625.     if(GfxBase)            CloseLibrary((struct Library *)GfxBase);
  626.     if(IntuitionBase)    CloseLibrary((struct Library *)IntuitionBase);
  627.     }
  628.  
  629. CheckMsg()
  630. {
  631. struct IntuiMessage *MyMsg;
  632.  
  633.     IMClass = 0;
  634.     MyMsg = (struct IntuiMessage*) GetMsg(MyPort);
  635.     if (MyMsg != NULL) {
  636.           IMClass = MyMsg -> Class;
  637.         ReplyMsg((struct Message *)MyMsg);
  638.     }
  639. }
  640.  
  641. CheckIntMsg()
  642. {
  643. struct IntuiMessage *MyMsg;
  644.     MenVal = 0;
  645.     MyMsg = (struct IntuiMessage*) GetMsg(IntPort);
  646.     if (MyMsg != NULL) {
  647.         MenVal = MyMsg -> Code;
  648.         ReplyMsg((struct Message *)MyMsg);
  649.     }
  650. }
  651.  
  652. void ErrorDisplay()
  653. {
  654. static    char    Err020[]    = "Sorry, but this Mandelbrot Generator requires a minimum configuration";
  655. static    char    Err021[]    = "of a 68881 and a 68020!";
  656. static    char    Err022[]    = "Use SManLb as a slow alternative!";
  657. static    char    Err023[]    = "Use the Close Gadget to Terminate.";
  658.     SetAPen(WBRast,1);
  659.     Move(WBRast,40,80);
  660.     Text(WBRast,(STRPTR)Err020,strlen(Err020));    
  661.     Move(WBRast,40,95);
  662.     Text(WBRast,(STRPTR)Err021,strlen(Err021));    
  663.     Move(WBRast,40,125);
  664.     Text(WBRast,(STRPTR)Err022,strlen(Err022));    
  665.     SetAPen(WBRast,3);
  666.     Move(WBRast,40,155);
  667.     Text(WBRast,(STRPTR)Err023,strlen(Err023));    
  668.     IMClass = 0;
  669.     while (IMClass != CLOSEWINDOW)    {
  670.         CheckMsg();
  671.         Delay(1);
  672.         }
  673. }
  674.  
  675. MakeLace()
  676. {
  677.     ScreenClose();
  678.     SUFlag = SUFlag | 0x2;
  679.     ViewSet();
  680.     ScreenSet();
  681. }
  682.  
  683. UnLace()
  684. {
  685.     ScreenClose();
  686.     SUFlag = SUFlag & 0xfffd;
  687.     ViewSet();
  688.     ScreenSet();
  689. }
  690.  
  691. MakeOver()
  692. {
  693.     ScreenClose();
  694.     SUFlag = SUFlag | 0x1;
  695.     ViewSet();
  696.     ScreenSet();
  697. }
  698.  
  699. MakeNorm()
  700. {
  701.     ScreenClose();
  702.     SUFlag = SUFlag & 0xfffe;
  703.     ViewSet();
  704.     ScreenSet();
  705. }
  706.  
  707. CountChange()
  708. {
  709.     if((MenVal & 0xff) == 2)    MaxCnt = MaxCnt + 10;
  710.     if((MenVal & 0xff) == 0x22)    MaxCnt = MaxCnt - 10;
  711.     if((MenVal & 0xff) == 0x42)    MaxCnt = 2*MaxCnt;
  712.     if((MenVal & 0xff) == 0x62) MaxCnt = MaxCnt/2;
  713.     if (MaxCnt < 10)    MaxCnt = 10;
  714.     WriteStuff();
  715.     ActivateWindow(IntWindow);
  716. }
  717.  
  718. ScreenChange()
  719. {
  720.     if((MenVal & 0xff) == 1)    MakeLace();
  721.     if((MenVal & 0xff) == 0x21)    UnLace();
  722.     if((MenVal & 0xff) == 0x41)    MakeOver();
  723.     if((MenVal & 0xff) == 0x61) MakeNorm();
  724.     WriteStuff();
  725.     ActivateWindow(IntWindow);
  726. }
  727.  
  728. void Restore()
  729. {
  730.     Factor = LastFactor;
  731.     XCenter = LastX;
  732.     YCenter = LastY;
  733. }
  734.  
  735. void PolyUpDate()
  736. {
  737.     PolyPnt = &PolyTab[0];
  738.     x2 = IntWindow -> MouseX;
  739.     *PolyPnt++ = x1;        /* Upper-Left Corner */
  740.     *PolyPnt++ = y1;
  741.     *PolyPnt++ = x2;        /* Upper-Right Corner */
  742.     *PolyPnt++ = y1;
  743.     DeltaX = x2 - x1;
  744.     DeltaY = SHeight*DeltaX/SWidth;
  745.     y2 = y1 + DeltaY;
  746.     *PolyPnt++ = x2;        /* Lower-Right Corner */
  747.     *PolyPnt++ = y2;
  748.     *PolyPnt++ = x1;        /* Lower-Left Corner */
  749.     *PolyPnt++ = y2;
  750.     *PolyPnt++ = x1;        /* Upper-Left Corner */
  751.     *PolyPnt++ = y1;
  752.     Move(CWRast,x1,y1);
  753.     PolyPnt = &PolyTab[0];
  754.     PolyDraw(CWRast,4,PolyPnt);
  755. }
  756.  
  757. /* Clear by reversing again */
  758. void PolyClear()
  759. {
  760.     PolyPnt = &PolyTab[0];
  761.     PolyDraw(CWRast,4,PolyPnt);
  762. }
  763. /*WaitChg will wait until there is at least a difference of 10 between
  764.  the original MouseX value and the new. */
  765.  
  766. void WaitChg()
  767. {
  768.     while ((x2 - x1) < 5)    {
  769.         x2 = IntWindow -> MouseX;
  770.         Delay(1);
  771.         }
  772. }
  773.  
  774. DoZoom()
  775. {
  776. double Ratio;
  777.     x1 = 0;
  778.     y1 = 0;
  779.     x2 = 0;
  780.     y2 = 0;
  781.     while (MenVal != SELECTDOWN)    {
  782.         CheckIntMsg();
  783.         }
  784.     x1 = IntWindow -> MouseX;
  785.     y1 = IntWindow -> MouseY;
  786.  
  787. /* Now prep for complementary polygon (i.e. rectangle) */
  788.     SetDrMd(CWRast,2);
  789.     WaitChg();
  790.     PolyUpDate();
  791.     while (MenVal != SELECTUP)    {
  792.         CheckIntMsg();
  793.         PolyClear();
  794.         PolyUpDate();
  795.         Delay(1);
  796.         }
  797. /* Clear Polygon and restore drawing mode */
  798.     PolyClear();
  799.     SetDrMd(CWRast,0);
  800.     if (LacMod == 0)    {
  801.         y1 = 2*y1;    /* Double y1 if not interlace */
  802.         }
  803.     LastFactor = Factor;
  804.     LastX = XCenter;
  805.     LastY = YCenter;
  806.  
  807.     Ratio = XWidth/DeltaX;
  808.     Factor = Ratio*Factor;
  809.  
  810.     XCenter = XCenter - (double)x1;
  811.     XCenter = Ratio*XCenter;
  812.     YCenter = YCenter - (double)y1;
  813.     YCenter = Ratio*YCenter;
  814.     MenVal = 0xf803;
  815. }
  816.  
  817. void Zoom()
  818. {
  819.     if((MenVal & 0xf0) == 0x00)    DoZoom();
  820.     if((MenVal & 0xf0) == 0x20)    Restore();
  821. }
  822.  
  823. SManMen()
  824. {
  825.         if (MenVal == 0xf800)    {
  826.             WriteStuff();
  827.             WBenchToFront();
  828.             WindowToFront(InfoWindow);
  829.             ActivateWindow(InfoWindow);
  830.             }
  831.         if (MenVal == 0xf840)    Save();
  832. }
  833.  
  834. void SingleLine()
  835. {
  836.  
  837.     xtemp = 0;
  838.  
  839.     while (xtemp < RightEdge)    { 
  840.         FuncFind();
  841.         xtemp++;
  842.         CheckMsg();
  843.         if (IMClass == CLOSEWINDOW)    {
  844.             ScreenToFront(IntScreen);
  845.             ActivateWindow(IntWindow);
  846.             }
  847.         CheckIntMsg();
  848.         if (MenVal)    {
  849.             if ((MenVal & 0xf) == 2)    CountChange();
  850.             if (MenVal == 0xf860)    return;
  851.             if ((MenVal & 0xf) == 1) return;
  852.             if ((MenVal & 0xf) == 3) {
  853.                 Zoom();
  854.                 return;
  855.                 }
  856.             if ((MenVal & 0xf) == 0)    {
  857.                 SManMen();
  858.                 if((MenVal & 0xff) == 0x20)    return;
  859.                 }
  860.             }
  861.         }
  862. }
  863.  
  864. FullSurface()
  865. {
  866.     SetRast(CWRast,0);
  867. /*    Execute((UBYTE *)"Date",0,0);*/
  868.     ytemp = NearEdge;
  869.     /* Now convert appropriate values to extended precision. */
  870.     ConExt();
  871.     while (ytemp < FarEdge)    {
  872.         SingleLine();        /*Draw next line*/
  873.         Delay(1);
  874.         if (MenVal)    {
  875.             if (MenVal == 0xf860)    return;
  876.             if ((MenVal & 0xf) == 1) return;
  877.             if ((MenVal & 0xf) == 3) return;
  878.             if ((MenVal & 0xff) == 0x20)    return;
  879.             }
  880.         ytemp++;
  881.     }
  882. /*    Execute((UBYTE *)"Date",0,0);*/
  883. }
  884.  
  885. Status()
  886. {
  887.     while (!MenVal)    {
  888.         Delay(1);
  889.         CheckMsg();
  890.         if (IMClass == CLOSEWINDOW)    {
  891.             ScreenToFront(IntScreen);
  892.             ActivateWindow(IntWindow);
  893.             MenVal = 0;
  894.             }
  895.         CheckIntMsg();
  896.         if (MenVal)    {
  897.             if (MenVal == -1) MenVal = 0;
  898.             if ((MenVal & 0xf) == 0)    {
  899.                 SManMen();
  900.                 if (MenVal == 0xf800) MenVal = 0;
  901.                 }
  902.             if ((MenVal & 0xf) == 1)    ScreenChange();
  903.             if ((MenVal & 0xf) == 2)    CountChange();
  904.             if ((MenVal & 0xf) == 3)    Zoom();
  905.             }
  906.     }
  907. }
  908.  
  909. void main()
  910. {
  911.  
  912.     MltPlr = 0xa0;
  913.     MaxCnt = 31;
  914.     LibsOpen();
  915.     WindowSet();
  916.     CurPrefs = GetPrefs(&MyNewPrefs,Pf_Size);
  917.     CurrentXOffset = CurPrefs -> ViewXOffset;
  918.     CurrentYOffset = CurPrefs -> ViewYOffset;
  919.     SysFlag = SysBase -> AttnFlags;
  920.     if (((SysFlag & AFB_68881)||(SysFlag & AFB_68882))&&((SysFlag & AFB_68020)||(SysFlag & AFB_68030)))    {
  921.         SUFlag = SUFlag & 0xfffe;    /*Clear ScnFlg*/
  922.         SUFlag = SUFlag & 0xfffd;    /*Clear LacFlg*/
  923.         ViewSet();
  924.         Factor = MltPlr;
  925.         XWidth = SWidth;
  926.         XHeight = SHeight;
  927.         HWidth = XC;
  928.         XCenter = XC;
  929.         HHeight = YC;
  930.         YCenter = YC;
  931. /*        CurPrefs = GetPrefs(&MyNewPrefs,Pf_Size);
  932.         CurrentXOffset = CurPrefs -> ViewXOffset;
  933.         CurrentYOffset = CurPrefs -> ViewYOffset;*/
  934. ns.Type        = CUSTOMSCREEN|SCREENBEHIND;
  935.         ScreenSet();
  936. ns.Type        = CUSTOMSCREEN;
  937.         WriteStuff();
  938.         ActivateWindow(InfoWindow);
  939.         MenVal = 0xf801;
  940.         while (MenVal != 0xf860)    {
  941.             FullSurface();
  942.             if ((MenVal & 0xf) == 1) ScreenChange();
  943.             Status();
  944.             }
  945.         }
  946.  
  947.     else {
  948.         ErrorDisplay();
  949.         }
  950.     MyNewPrefs.ViewXOffset = CurrentXOffset;
  951.     MyNewPrefs.ViewYOffset = CurrentYOffset;
  952.     SetPrefs(&MyNewPrefs,Pf_Size,FALSE);
  953.     ScreensClose();
  954.     LibsClose();
  955. }
  956.